#!/usr/bin/perl
#translate.pl -- translate nucleic acid sequence to protein sequence
#           according to standard genetic code
# set up table of standard genetic code
%standardgeneticcode = (
"ttt"=> "Phe", "tct"=> "Ser", "tat"=> "Tyr", "tgt"=> "Cys",
"ttc"=> "Phe", "tcc"=> "Ser", "tac"=> "Tyr", "tgc"=> "Cys",
"tta"=> "Leu", "tca"=> "Ser", "taa"=> "TER", "tga"=> "TER",
"ttg"=> "Leu", "tcg"=> "Ser", "tag"=> "TER", "tgg"=> "Trp",
"ctt"=> "Leu", "cct"=> "Pro", "cat"=> "His", "cgt"=> "Arg",
"ctc"=> "Leu", "ccc"=> "Pro", "cac"=> "His", "cgc"=> "Arg",
"cta"=> "Leu", "cca"=> "Pro", "caa"=> "Gln", "cga"=> "Arg",
"ctg"=> "Leu", "ccg"=> "Pro", "cag"=> "Gln", "cgg"=> "Arg",
"att"=> "Ile", "act"=> "Thr", "aat"=> "Asn", "agt"=> "Ser",
"atc"=> "Ile", "acc"=> "Thr", "aac"=> "Asn", "agc"=> "Ser",
"ata"=> "Ile", "aca"=> "Thr", "aaa"=> "Lys", "aga"=> "Arg",
"atg"=> "Met", "acg"=> "Thr", "aag"=> "Lys", "agg"=> "Arg",
"gtt"=> "Val", "gct"=> "Ala", "gat"=> "Asp", "ggt"=> "Gly",
"gtc"=> "Val", "gcc"=> "Ala", "gac"=> "Asp", "ggc"=> "Gly",
"gta"=> "Val", "gca"=> "Ala", "gaa"=> "Glu", "gga"=> "Gly",
"gtg"=> "Val", "gcg"=> "Ala", "gag"=> "Glu", "ggg"=> "Gly"
);
# process input data
while ($line = <DATA>) {                        # read in line of input
   print "$line";                        # transcribe to output
   chop();                               # remove end-of-line character
   @triplets = unpack("a3" x (length($line)/3), $line); # pull out successive triplets
   foreach $codon (@triplets) {                   # loop over triplets
      print "$standardgeneticcode{$codon}";            # print out translation of each
   }                                  # end loop on triplets
   print "\n\n";                         # skip line on output
}                                     # end loop on input lines
# what follows is input data
__END__
atgcatccctttaataatgctttaacccaa
tctgtctga

